package cn.edu.shiep.aurora.gunwar.rule.junit4;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

import cn.edu.shiep.aurora.gunwar.rule.RuleDegreeCalculator;

public class RuleDegreeCalculatorTest {
	private RuleDegreeCalculator cal=new RuleDegreeCalculator();
	@Before
	public void setUp() throws Exception {
	}

	@Test
	public void testGetOclockDirection() {
		int i1=cal.getOclockDirection(0);
		assertEquals(0, i1);
		int i2=cal.getOclockDirection(-90);
		assertEquals(9, i2);
		int i3=cal.getOclockDirection(90);
		assertEquals(3, i3);
		int i4=cal.getOclockDirection(270);
		assertEquals(9, i4);
	}
	private double delta=0.0001;
	@Test
	public void testDegreeUnify() {
		double d1=cal.degreeUnify(350);
		assertEquals(350.0, d1,delta);
		double d2=cal.degreeUnify(-350);
		assertEquals(10, d2,delta);
		double d3=cal.degreeUnify(-170);
		assertEquals(190, d3,delta);
	}

	@Test
	public void testGetD1ToD2OclockDirection() {
		int i1=cal.getD1ToD2OclockDirection(0, 90);
		assertEquals(3, i1);
		int i2=cal.getD1ToD2OclockDirection(-90, 60);
		assertEquals(5, i2);
		int i3=cal.getD1ToD2OclockDirection(-180, 180);
		assertEquals(0, i3);
		int i4=cal.getD1ToD2OclockDirection(0,270 );
		assertEquals(9, i4);
	}

	@Test
	public void testGetD1toOclockDirectionToDegree() {
		double d1=cal.getD1toOclockDirectionToDegree(0, 3);
		assertEquals(90.0, d1,delta);
		double d2=cal.getD1toOclockDirectionToDegree(350,3);
		assertEquals(80, d2,delta);
		double d3=cal.getD1toOclockDirectionToDegree(-90,3);
		assertEquals(0, d3,delta);
	}

	@Test
	public void testIncludeDegree() {
		double d1=cal.includeDegree(0, 90);
		assertEquals(90, d1,delta);
		 d1=cal.includeDegree(-90, 90);
		assertEquals(180, d1,delta);
		 d1=cal.includeDegree(90, -10);
			assertEquals(260, d1,delta);
			d1=cal.includeDegree(350, -10);
			assertEquals(0, d1,delta);
	}

}
